package com.googlecode.payroll

import static com.googlecode.payroll.util.RoleUtil.*

class PaymentCalculationService {

    static transactional = false 

    def workingHoursTotalizerCreateService
    def salesAmountTotalizerCreateService

    List<Salary> calculateSalary(String month) {

        def workingHoursTotalizer = workingHoursTotalizerCreateService.create(month)
        def salesAmountTotalizer  = salesAmountTotalizerCreateService.create(month)

        def salaryList = []
        Employee.list().each() {
            def paymentCalculator = assign(it, PaymentCalculator)
            int payment = paymentCalculator.calculate(workingHoursTotalizer, salesAmountTotalizer)
            log.info(it.name + ":" + payment)
            salaryList += new Salary(employee:it.name, payment:payment)
        }
        salaryList
    }
}
